__author__ = 'user'
from selenium.common.exceptions import NoSuchElementException


class BasePage(object):

    PAGE_ADDRESS = r''

    def __init__(self, driver):
        self.driver = driver

    def open(self):
        self.driver.get(self.PAGE_ADDRESS)

    def close(self):
        self.driver.close()

    def searchElementsByLocator(self, locator):
        by = locator[0]
        value = locator[1]

        try:
            if len(self.driver.find_elements(by, value)) == 1:
                elements = self.driver.find_element(by, value)
            else:
                elements = self.driver.find_elements(by, value)

        except NoSuchElementException:
            elements = None

        return elements